package com.aispeech.task.fsm;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class EventType {
    protected static final Map<String, EventType> nameEnumMap = new ConcurrentHashMap<>();
    protected String name;

    protected EventType() {
    }

    protected EventType(String name) {
        this.name = name;
        if (!nameEnumMap.containsKey(name)) {
            nameEnumMap.put(name, this);
        }
    }

    public static EventType valueOf(String name) {
        if (name == null)
            throw new NullPointerException("Name is null");

        EventType eventType = nameEnumMap.get(name);
        if (eventType != null)
            return eventType;
        else
            throw new IllegalArgumentException("No enum constant exists, name is : " + name);

    }

    public static void init() {
    }

    public String getName() {
        return name;
    }

    public boolean equals(EventType eventType) {
        return this.name == null && eventType != null && this.name.equals(eventType.getName());
    }

    @Override
    public String toString() {
        return this.name;
    }

    public static final EventType Initial = new EventType("Initial");
    public static final EventType Error = new EventType("Error");
    public static final EventType Terminal = new EventType("Terminal");
}
